********************************************************************************
* Political Engagement and Immigration Issue Salience
* ANES 2024 Pilot Study – Cleaned and Customized Do-File
* Author: Muhammad Hassan Bin Afzal, Ph.D.  and Foluke Omosun, Ph.D.
********************************************************************************



********************************************************************************
* STEP 2: Recode Dependent Variables (DV)
********************************************************************************

* Importance of Illegal Immigration (Primary DV)
drop if imp_immig == -1
recode imp_immig (1=5) (2=4) (3=3) (4=2) (5=1), gen(immigration_importance)
label define immig_lbl 5 "Extremely Important" 4 "Very Important" 3 "Moderately Important" 2 "Slightly Important" 1 "Not Important"
label values immigration_importance immig_lbl
label var immigration_importance "Importance of Illegal Immigration"

* Views on Legal Immigration (Secondary DV)
drop if border_legal == -1
recode border_legal (1=5) (2=4) (3=3) (4=2) (5=1), gen(legal_immigration_views)
label define legal_lbl 5 "A lot easier" 4 "Somewhat easier" 3 "About the same" 2 "Somewhat harder" 1 "A lot harder"
label values legal_immigration_views legal_lbl
label var legal_immigration_views "Views on Legal Immigration"

********************************************************************************
* STEP 3: Create Political Engagement Index (Main IV)
********************************************************************************

recode mobil_talk (1=1) (2=0) (-1=.) (-7=.), gen(talk_binary)
recode mobil_online (1=1) (2=0) (-1=.), gen(online_binary)
recode mobil_rally (1=1) (2=0) (-1=.) (-7=.), gen(rally_binary)
recode mobil_button (1=1) (2=0) (-1=.), gen(button_binary)
recode mobil_work (1=1) (2=0) (-1=.), gen(work_binary)

* Sum index
gen political_engagement_index = talk_binary + online_binary + rally_binary + button_binary + work_binary
label var political_engagement_index "Political Engagement Index (0–5)"

* Descriptive statistics
summarize political_engagement_index
tab political_engagement_index

* Reliability - Cronbach's Alpha
alpha talk_binary online_binary rally_binary button_binary work_binary

* Exploratory Factor Analysis (EFA)
factor talk_binary online_binary rally_binary button_binary work_binary, pcf

* Confirmatory Factor Analysis (CFA)
sem (Political_Engagement -> talk_binary online_binary rally_binary button_binary work_binary)
estat gof, stats(all)

********************************************************************************
* STEP 4: Demographic Controls
********************************************************************************

* Gender
recode gender (1 = 1 "Male") (2 = 0 "Female") (-1 = .), gen(male)
label var male "Gender: Male"

* Age
gen log_age = log(age)
label var log_age "Log of Age"

* Education (Already coded as 'educ')

* Income
drop if faminc_new == 97 | faminc_new == -7
recode faminc_new (12/16 = 12), gen(income)
label define income_lbl 1 "Less than $10K" 2 "$10K–$19K" 3 "$20K–$29K" 4 "$30K–$39K" 5 "$40K–$49K" 6 "$50K–$59K" 7 "$60K–$69K" 8 "$70K–$79K" 9 "$80K–$99K" 10 "$100K–$119K" 11 "$120K–$149K" 12 "$150K and above"
label values income income_lbl
label var income "Household Income"

********************************************************************************
* STEP 5: Social Trust Variable (Zinger Control)
********************************************************************************

recode trust_soctrust (1=5) (2=4) (3=3) (4=2) (5=1) (-7=.), gen(social_trust)
label var social_trust "Generalized Social Trust"
label define socialtrust_lbl ///
    1 "Never trust others" ///
    2 "Trust some of the time" ///
    3 "Trust about half the time" ///
    4 "Trust most of the time" ///
    5 "Always trust others"

label values social_trust socialtrust_lbl

********************************************************************************
* STEP 6: Party Identification Dummies
********************************************************************************

gen democrat = (pid3 == 1)
gen republican = (pid3 == 2)
gen independent = (pid3 == 3)
label var democrat "Democrat"
label var republican "Republican"
label var independent "Independent"

********************************************************************************
* STEP 7: Interaction Terms
********************************************************************************

gen dem_engage = democrat * political_engagement_index
label var dem_engage "Interaction: Democrat x Engagement"

gen rep_engage = republican * political_engagement_index
label var rep_engage "Interaction: Republican x Engagement"

* Create dummy variable for living in a big city
gen big_city = 0
replace big_city = 1 if urbanicity2 == 1
label variable big_city "Lives in a big city"
* Interaction: Democrat x Big City
gen dem_bigcity = democrat * big_city
label variable dem_bigcity "Interaction: Democrat x Big City"

* Interaction: Republican x Big City
gen rep_bigcity = republican * big_city
label variable rep_bigcity "Interaction: Republican x Big City"

********************************************************************************
* STEP 8: Complete Case Flag
********************************************************************************

gen complete_case = !missing(immigration_importance, legal_immigration_views, political_engagement_index, male, big_city, log_age, educ, income, democrat, republican, social_trust, dem_bigcity,rep_bigcity )

********************************************************************************
* STEP 9: Ordered Logistic Models
********************************************************************************

* Model 1 – Bivariate
ologit legal_immigration_views political_engagement_index if complete_case [pweight=weight], or
est store Model1

* Model 2 – Multivariate
ologit legal_immigration_views political_engagement_index male log_age educ income democrat republican social_trust big_city if complete_case [pweight=weight], or
est store Model2

* Model 3 – With Interactions
ologit legal_immigration_views political_engagement_index male log_age educ income democrat republican social_trust big_city dem_bigcity rep_bigcity  if complete_case [pweight=weight], or
est store Model3
esttab Model1 Model2 Model3, eform stats(N ll bic aic r2_p, fmt(0 3 3 3 3)) star


* Coefplot: Main Models
coefplot (Model1, label("Bivariate") mcolor(blue)) ///
         (Model2, label("Controls") mcolor(red)) ///
         (Model3, label("Interactions") mcolor(green)), ///
         xline(1, lcolor(black)) ///
         drop(_cons) ///
         legend(on) ///
         title("Political Engagement Index(PAX) and Legal Immigration Views") ///
         scheme(white_tableau)
		 
********************************************************************************
* STEP 9B: Assumption Check – Parallel Lines (Brant/Gologit2)
********************************************************************************
gologit2 legal_immigration_views political_engagement_index male log_age educ income ///
         democrat republican social_trust big_city if complete_case [pweight=weight], autofit
* Brant test not usable due to weights: r(9992)
* gologit2 with 'autofit' used as a robust alternative to test proportional odds
* All variables met the assumption except social_trust (p = 0.0339)
* However, global Wald test p = 0.0756 → Fail to reject null → assumption holds overall
* 'social_trust' retained due to its strong theoretical and empirical relevance to issue salience

********************************************************************************
* STEP 10: Subset Analysis by Party ID
********************************************************************************

ologit legal_immigration_views political_engagement_index male log_age educ income social_trust big_city if democrat == 1 & complete_case [pweight=weight], or
est store DemSubset

ologit legal_immigration_views political_engagement_index male log_age educ income social_trust big_city if republican == 1 & complete_case [pweight=weight], or
est store RepSubset

ologit legal_immigration_views political_engagement_index male log_age educ income social_trust big_city if independent == 1 & complete_case [pweight=weight], or
est store IndSubset

esttab DemSubset RepSubset IndSubset, eform se star stats(N ll bic aic r2_p, fmt(0 3 3 3 3))


********************************************************************************
* STEP 11: Output Models
********************************************************************************



coefplot (DemSubset, label("Democrats") mcolor(blue)) ///
         (RepSubset, label("Republicans") mcolor(red)) ///
         (IndSubset, label("Independents") mcolor(green)), ///
         xline(1, lcolor(black)) ///
         drop(_cons) ///
         legend(on) ///
         title("Legal Immigration Views and Political Engagement (PAX)") ///
         scheme(white_tableau)

********************************************************************************
* END OF DO-FILE
********************************************************************************


	**xx-----------------------------------------------------------------------------xx**

* ===========================================
* FULL SAMPLE MODEL (No Partisan Subsetting)
* ===========================================
ologit legal_immigration_views i.political_engagement_index male log_age educ income ///
    democrat republican social_trust big_city if complete_case [pweight=weight], vce(robust)

* Full Sample: A Lot Harder
margins i.political_engagement_index, predict(outcome(1))
marginsplot, name(full_harder, replace) title("Full Sample: A Lot Harder") noci scheme(white_tableau)

* Full Sample: A Lot Easier
margins i.political_engagement_index, predict(outcome(5))
marginsplot, name(full_easier, replace) title("Full Sample: A Lot Easier") noci scheme(white_tableau)

* ================================
* DEMOCRATS
* ================================
ologit legal_immigration_views political_engagement_index male log_age educ income ///
    social_trust big_city if democrat == 1 & complete_case [pweight=weight], vce(robust)

* Democrats: A Lot Harder
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(1))
marginsplot, name(dem_harder, replace) title("Democrats: A Lot Harder") noci scheme(white_tableau)

* Democrats: A Lot Easier
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(5))
marginsplot, name(dem_easier, replace) title("Democrats: A Lot Easier") noci scheme(white_tableau)

* ================================
* REPUBLICANS
* ================================
ologit legal_immigration_views political_engagement_index male log_age educ income ///
    social_trust big_city if republican == 1 & complete_case [pweight=weight], vce(robust)

* Republicans: A Lot Harder
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(1))
marginsplot, name(rep_harder, replace) title("Republicans: A Lot Harder") noci scheme(white_tableau)

* Republicans: A Lot Easier
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(5))
marginsplot, name(rep_easier, replace) title("Republicans: A Lot Easier") noci scheme(white_tableau)

* ================================
* INDEPENDENTS
* ================================
ologit legal_immigration_views political_engagement_index male log_age educ income ///
    social_trust big_city if independent == 1 & complete_case [pweight=weight], vce(robust)

* Independents: A Lot Harder
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(1))
marginsplot, name(ind_harder, replace) title("Independents: A Lot Harder") noci scheme(white_tableau)

* Independents: A Lot Easier
margins, at(political_engagement_index=(0 1 2 3 4 5)) predict(outcome(5))
marginsplot, name(ind_easier, replace) title("Independents: A Lot Easier") noci scheme(white_tableau)

* ================================
* Combine All 8 Graphs
* ================================
graph combine full_harder dem_harder rep_harder ind_harder ///
              full_easier dem_easier rep_easier ind_easier, ///
    col(4) imargin(4 4 4 4) ///
    title("Predicted Probabilities by Political Engagement and Partisan Identity") ///
    subtitle("Views on Legal Immigration: A Lot Harder vs A Lot Easier") ///
    ycommon xcommon scheme(white_tableau)
	
	
	**xx-----------------------------------------------------------------------------xx**

* ================================
* FULL SAMPLE - EDUCATION
* ================================
ologit legal_immigration_views i.educ male log_age political_engagement_index income ///
    democrat republican social_trust big_city if complete_case [pweight=weight], vce(robust)

* Full Sample – Harder
margins i.educ, predict(outcome(1))
marginsplot, name(full_educ_harder, replace) ///
    title("Full Sample – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Full Sample – Easier
margins i.educ, predict(outcome(5))
marginsplot, name(full_educ_easier, replace) ///
    title("Full Sample – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* DEMOCRATS
* ================================
ologit legal_immigration_views i.educ male log_age political_engagement_index income ///
    social_trust big_city if democrat == 1 & complete_case [pweight=weight], vce(robust)

* Democrats – Harder
margins i.educ, predict(outcome(1))
marginsplot, name(dem_educ_harder, replace) ///
    title("Democrats – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Democrats – Easier
margins i.educ, predict(outcome(5))
marginsplot, name(dem_educ_easier, replace) ///
    title("Democrats – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* REPUBLICANS
* ================================
ologit legal_immigration_views i.educ male log_age political_engagement_index income ///
    social_trust big_city if republican == 1 & complete_case [pweight=weight], vce(robust)

* Republicans – Harder
margins i.educ, predict(outcome(1))
marginsplot, name(rep_educ_harder, replace) ///
    title("Republicans – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Republicans – Easier
margins i.educ, predict(outcome(5))
marginsplot, name(rep_educ_easier, replace) ///
    title("Republicans – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* INDEPENDENTS
* ================================
ologit legal_immigration_views i.educ male log_age political_engagement_index income ///
    social_trust big_city if independent == 1 & complete_case [pweight=weight], vce(robust)

* Independents – Harder
margins i.educ, predict(outcome(1))
marginsplot, name(ind_educ_harder, replace) ///
    title("Independents – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Independents – Easier
margins i.educ, predict(outcome(5))
marginsplot, name(ind_educ_easier, replace) ///
    title("Independents – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* COMBINE ALL 8 GRAPHS
* ================================
graph combine full_educ_harder dem_educ_harder rep_educ_harder ind_educ_harder ///
              full_educ_easier dem_educ_easier rep_educ_easier ind_educ_easier, ///
    col(4) imargin(4 4 4 4) ///
    title("Immigration Views by Education and Party") ///
    subtitle("Probability: Harder vs Easier Legal Immigration") ///
    ycommon xcommon scheme(white_tableau)

	**xx-----------------------------------------------------------------------------xx**
	
* ================================
* FULL SAMPLE – SOCIAL TRUST
* ================================
ologit legal_immigration_views i.social_trust male log_age educ political_engagement_index income ///
    democrat republican big_city if complete_case [pweight=weight], vce(robust)

* Full Sample – Harder
margins i.social_trust, predict(outcome(1))
marginsplot, name(full_trust_harder, replace) ///
    title("Full Sample – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Full Sample – Easier
margins i.social_trust, predict(outcome(5))
marginsplot, name(full_trust_easier, replace) ///
    title("Full Sample – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* DEMOCRATS
* ================================
ologit legal_immigration_views i.social_trust male log_age educ political_engagement_index income ///
    big_city if democrat == 1 & complete_case [pweight=weight], vce(robust)

* Democrats – Harder
margins i.social_trust, predict(outcome(1))
marginsplot, name(dem_trust_harder, replace) ///
    title("Democrats – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Democrats – Easier
margins i.social_trust, predict(outcome(5))
marginsplot, name(dem_trust_easier, replace) ///
    title("Democrats – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* REPUBLICANS
* ================================
ologit legal_immigration_views i.social_trust male log_age educ political_engagement_index income ///
    big_city if republican == 1 & complete_case [pweight=weight], vce(robust)

* Republicans – Harder
margins i.social_trust, predict(outcome(1))
marginsplot, name(rep_trust_harder, replace) ///
    title("Republicans – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Republicans – Easier
margins i.social_trust, predict(outcome(5))
marginsplot, name(rep_trust_easier, replace) ///
    title("Republicans – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* INDEPENDENTS
* ================================
ologit legal_immigration_views i.social_trust male log_age educ political_engagement_index income ///
    big_city if independent == 1 & complete_case [pweight=weight], vce(robust)

* Independents – Harder
margins i.social_trust, predict(outcome(1))
marginsplot, name(ind_trust_harder, replace) ///
    title("Independents – Harder") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* Independents – Easier
margins i.social_trust, predict(outcome(5))
marginsplot, name(ind_trust_easier, replace) ///
    title("Independents – Easier") ///
    scheme(white_tableau) ///
    noci ///
    xlabel(, angle(45))

* ================================
* COMBINE ALL 8 GRAPHS
* ================================
graph combine full_trust_harder dem_trust_harder rep_trust_harder ind_trust_harder ///
              full_trust_easier dem_trust_easier rep_trust_easier ind_trust_easier, ///
    col(4) imargin(4 4 4 4) ///
    title("Immigration Views by Social Trust and Party") ///
    subtitle("Probability: Harder vs Easier Legal Immigration") ///
    ycommon xcommon scheme(white_tableau)
